#include "stdafx.h"

#include "gtest/gtest.h"
#include "DominoManager.h"

TEST(domino, DominoManager_HappyDay) {
	_CrtMemState _ms;
	_CrtMemCheckpoint(&_ms);
	{
		dgame::DominoManager dManager;
		ASSERT_EQ(dManager.size(), 0);
		{
			dManager.addDomino(dgame::Domino(1,2));
		}
		ASSERT_EQ(dManager[0].getLeft(), 1);
		ASSERT_EQ(dManager[0].getRight(), 2);
		ASSERT_EQ(dManager.size(), 1);
	}
	{
		dgame::DominoManager dManager;
		ASSERT_EQ(dManager.size(), 0);
		{
			dManager.addDomino(dgame::Domino(1,2));
		}

		dgame::DominoManager dM2 = dManager;
		ASSERT_EQ(dM2[0].getLeft(), 1);
		ASSERT_EQ(dM2[0].getRight(), 2);
		ASSERT_EQ(dM2.size(), 1);
	}
	_CrtMemDumpAllObjectsSince(&_ms);
}

TEST(domino, dominoManager_deleteDomino) {
	_CrtMemState _ms;
	_CrtMemCheckpoint(&_ms);
	{
		dgame::DominoManager dManager;
		ASSERT_EQ(dManager.size(), 0);
		{
			dManager.addDomino(dgame::Domino(1,2));
			ASSERT_EQ(dManager.size(), 1);
			dManager.deleteDomino(dManager[0]);
		}
		ASSERT_EQ(dManager.size(), 0);
	}
	_CrtMemDumpAllObjectsSince(&_ms);
}

TEST(domino, DominoManager_DominoNotFoundedException) {
	_CrtMemState _ms;
	_CrtMemCheckpoint(&_ms);
	{
		dgame::DominoManager dManager;
		ASSERT_EQ(dManager.size(), 0);
		{
			dManager.addDomino(dgame::Domino(1,2));
			ASSERT_EQ(dManager.size(), 1);
			ASSERT_THROW(dManager.deleteDomino(dgame::Domino(2,3)), dgame::DominoNotFoundedException);
		}
		ASSERT_EQ(dManager.size(), 1);
	}
	_CrtMemDumpAllObjectsSince(&_ms);
}

TEST(domino, DominoManager_OutOfRangeException) {
	_CrtMemState _ms;
	_CrtMemCheckpoint(&_ms);
	{
		dgame::DominoManager dManager;
		ASSERT_EQ(dManager.size(), 0);
		{
			dManager.addDomino(dgame::Domino(1,2));
			ASSERT_EQ(dManager.size(), 1);
			ASSERT_THROW(dManager[1], dgame::OutOfRangeException);
		}
		ASSERT_EQ(dManager.size(), 1);
	}
	_CrtMemDumpAllObjectsSince(&_ms);
}

TEST(domino, DominoManager_checkDomino) {
	_CrtMemState _ms;
	_CrtMemCheckpoint(&_ms);
	{
		dgame::DominoManager dManager;
		ASSERT_EQ(dManager.size(), 0);
		{
			dManager.addDomino(dgame::Domino(1,2));
			ASSERT_TRUE(dManager.checkDomino(dgame::Domino(2,1)));
			ASSERT_FALSE(dManager.checkDomino(dgame::Domino(3,1)));
		}
		ASSERT_EQ(dManager.size(), 1);
	}
	_CrtMemDumpAllObjectsSince(&_ms);
}

TEST(domino, DominoManager_shuffleDomino) {
	_CrtMemState _ms;
	_CrtMemCheckpoint(&_ms);
	{
		dgame::DominoManager dManager;
		ASSERT_EQ(dManager.size(), 0);
		{
			dManager.addDomino(dgame::Domino(1,1));
			dManager.addDomino(dgame::Domino(1,2));
			dManager.addDomino(dgame::Domino(1,3));
			dManager.addDomino(dgame::Domino(1,4));
			dManager.addDomino(dgame::Domino(1,5));
			dManager.addDomino(dgame::Domino(1,6));
			dManager.addDomino(dgame::Domino(3,5));
			dManager.addDomino(dgame::Domino(3,6));
		}
		dManager.shuffleDomino();
		bool success = false;
		for (unsigned int i = 0; i < dManager.size() - 1; i++)
		{
			if(dManager[i].getPoints() > dManager[i+1].getPoints())
			{
				success = true;
				break;
			}
		}
		ASSERT_TRUE(success);
	}
	_CrtMemDumpAllObjectsSince(&_ms);
}